//封装用户相关的接口函数
import { request } from "@/utils/request";
import type {
  User,
  CodeType,
  UserInfo,
  PatientList,
  Patient,
  KnowledgePage,
  KnowledgeParams,
  DoctorPage,
  PageParams,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreData, ConsultOrderPreParams,ConsultOrderItem, PartialConsult
} from "@/types/user.d.ts";
export const loginPasswordAPI = (mobile: string, password: string) =>
  request<User>("/login/password", "post", { mobile, password });
export const sendCodeAPI = (mobile: string, type: CodeType) =>
  request("/code", "get", { mobile, type });
export const loginCodeAPI = (mobile: string, code: string) =>
  request<User>("/login", "POST", { mobile, code });
// 获取个人信息
export const getUserInfoAPI = () => request<UserInfo>("/patient/myUser");
export const getPatientListAPI = () => request<PatientList>("/patient/mylist");
export const addPatientAPI = (patient: Patient) =>
  request("/patient/add", "POST", patient);
// 删除患者信息
export const delPatientAPI = (id: string) =>
  request(`/patient/del/${id}`, "DELETE");
// 编辑患者信息
export const editPatientAPI = (patient: Patient) =>
  request("/patient/update", "PUT", patient);
export const getKnowledgePageAPI = (params: KnowledgeParams) =>
  request<KnowledgePage>("/patient/home/knowledge", "GET", params);
//   推荐关注医生 接口函数
  export const getDoctorPageAPI = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

  export const followOrUnfollowAPI = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', { id, type })

  export const getAllDepAPI = () => request<TopDep[]>('/dep/all')
  export const uploadImageAPI = (file: File) => {
    const fd = new FormData()
    fd.append('file', file)
    return request<Image>('/upload', 'POST', fd)
  }
  // 拉取预支付订单信息
export const getConsultOrderPreAPI = (params: ConsultOrderPreParams) =>
request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)
// 查询患者详情
export const getPatientDetailAPI = (id: string) => request<Patient>(`/patient/info/${id}`)
// 生成订单
export const createConsultOrderAPI = (data: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

  export const getConsultOrderPayUrlAPI = (params: {
    paymentMethod: 0 | 1
    orderId: string
    payCallback: string
  }) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

  export const getConsultOrderDetailAPI = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
